import java.io.*;
import java.util.*;
import java.util.Scanner;

public class Start {
	
	public static void main(String args[]) throws IOException {
		MyStack workStack = null; 
		OutputStreamWriter consoleOutputStream = null;
		
		BufferedReader inputStream = null;
		PrintWriter outputStream = null;

		
	   
		try {
			workStack = new MyStack(); 
			
			Scanner scan = new Scanner(System.in);
		    System.out.println("Enter the name of file in such way: name_of_file.txt ");
		    String s = scan.next();
			
			inputStream = new BufferedReader(new FileReader(s));
			outputStream = new PrintWriter(new FileWriter("output.txt"));
			consoleOutputStream = new OutputStreamWriter(System.out);
			
			List<String> inputStrings = new ArrayList<String>();
			String l;
			
			while ((l = inputStream.readLine()) != null) {
				//consoleOutputStream.write(l + "\n");
				System.out.println(l);
				inputStrings.add(l);
			}
			System.out.println("\n");		
			for (int i = inputStrings.size() - 1; i >=0; i--) {
				for (int j = 0; j < inputStrings.get(i).length(); j++) {
					workStack.push(inputStrings.get(i).charAt(j));
				}
				
				int tempLength = workStack.getLength();				
				for (int j = 0; j < tempLength; j++) {
					outputStream.print(workStack.pop());
				}
				System.out.print("\n");
				outputStream.print("\n");
			}
			
		} finally {
			if (inputStream != null) {
				inputStream.close();
			}
			if (outputStream != null) {
				outputStream.close();
			}
			if (consoleOutputStream != null){
				consoleOutputStream.close();
			}
		}	
	}
}
